﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;
using System.Reflection;
using System.IO;

namespace RCSnake
	{
	abstract class Shape
		{
		/*---------------------------------------------*\
		|*                 Attributs                   *|
		\*---------------------------------------------*/
		//input
		protected Area m_area;
		protected Size m_size;
		protected Point m_position;

		protected Rectangle m_rectangleBlock;
		protected SolidBrush m_solidBrush;
		protected int m_directionX;
		protected int m_directionY;
		protected int m_oldDirectionX;
		protected int m_oldDirectionY;
		protected Image m_img;

		/*---------------------------------------------*\
		|*                Constructeur                 *|
		\*---------------------------------------------*/
		public Shape(Area area, Size size, Point position)
			{
			m_size = size;
			m_area = area;
			m_position = position;
			m_rectangleBlock = new Rectangle(this.position, m_size);
			m_solidBrush = new SolidBrush(Color.Transparent);
			m_directionX = (int)Direction.POSITIVE;
			m_directionY = (int)Direction.NULL;
			m_oldDirectionX = (int)Direction.NULL;
			m_oldDirectionY = (int)Direction.NULL;
			}

		/*---------------------------------------------*\
		|*               Methodes public               *|
		\*---------------------------------------------*/
		public virtual void draw(PaintEventArgs e)
			{
			m_rectangleBlock.X = this.position.X;
			m_rectangleBlock.Y = this.position.Y;
			e.Graphics.FillRectangle(m_solidBrush, m_rectangleBlock);

			if(m_img != null)
				{
				e.Graphics.DrawImage(m_img, position);
				}
			}

		/*---------------------*\
		|*      get / set      *|
		\*---------------------*/
		public Point position
			{
			get { return m_position; }
			set { m_position = value; }
			}

		public Size size
			{
			get { return m_size; }
			set { m_size = value; }
			}

		public int directionX
			{
			get { return m_directionX; }
			set { m_directionX = value; }
			}

		public int directionY
			{
			get { return m_directionY; }
			set { m_directionY = value; }
			}

		public int oldDirectionX
			{
			get { return m_oldDirectionX; }
			set { m_oldDirectionX = value; }
			}

		public int oldDirectionY
			{
			get { return m_oldDirectionY; }
			set { m_oldDirectionY = value; }
			}

		public void changePosition(int dx, int dy)
			{
			this.position = new Point(this.position.X + dx, this.position.Y + dy);
			}

		public Rectangle rectangleBlock
			{
			get { return m_rectangleBlock; }
			}

		public Area area
			{
			get { return m_area; }
			}

		public Image image
			{
			get { return m_img; }
			}

		/*---------------------*\
		|*        static       *|
		\*---------------------*/
		static public Image getResourceImage(String nameFile)
			{
			Assembly assembly;
			Stream imageStream;
			String str = "RCSnake.";
			str += nameFile;

			try
				{
				assembly = Assembly.GetExecutingAssembly();
				imageStream = assembly.GetManifestResourceStream(str);
				return Image.FromStream(imageStream);
				}
			catch(Exception e)
				{
				MessageBox.Show(e.ToString());
				return null;
				}
			}
		}
	}
